package com.itmake.sample.async.manager;

import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * 确保应用退出时能关闭后台线程
 *
 * @author Amjacks
 * @since 2023/08/10
 */
@Component
public class ShutdownManager {
    @PreDestroy
    public void destroy() {
        shutdownAsyncManager();
    }

    /**
     * 停止异步执行任务
     */
    private void shutdownAsyncManager() {
        try {
            // 关闭后台任务任务线程池
            AsyncManager.me().shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
